package com.dongdongsop.data;

import com.dongdongsop.em.ResultEnum;

import java.io.Serializable;

/**
 * ajax返回值 : 如果分页就把page扔进去 ， 如果是根据id查询 实体类扔进去 如果是集合 把list扔进去
 */
public class AjaxResult<T> implements Serializable {
    private Integer code;
    private String message;
    private T data;

    public static AjaxResult OK(){
        AjaxResult result = new AjaxResult();
        result.setCode(ResultEnum.SUCCESS.getStatus()); //自定义成功返回码
        result.setMessage(ResultEnum.SUCCESS.getStatusInfo());
        return result;
    }

    public static AjaxResult ERROR(){
        AjaxResult result = new AjaxResult();
        result.setCode(ResultEnum.ERROR.getStatus()); //自定义成功返回码
        result.setMessage(ResultEnum.ERROR.getStatusInfo());
        return result;
    }

    public static AjaxResult R(ResultEnum resultEnum){
        AjaxResult result = new AjaxResult();
        result.setCode(resultEnum.getStatus()); //自定义成功返回码
        result.setMessage(resultEnum.getStatusInfo());
        return result;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public AjaxResult<T> setData(T data) {
        this.data = data;
        return this;
    }
}
